Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCHEDULE] New Reduction Mode for Tensorize #727

Merged
merged 5 commits into from
Dec 27, 2017
Merged

[SCHEDULE] New Reduction Mode for Tensorize #727

merged 5 commits into from
Dec 27, 2017

Conversation

kun-zh
Copy link
Contributor

@kun-zh kun-zh commented Dec 26, 2017

…e 714. @tqchen , This fix can resolve the original issue which I raised. Please review it , thanks.

Copy link
Member

@tqchen tqchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some codestyle problem, you can reproduce locally via make lint. Other comments are explicitly inlined

Stmt body,
Stmt update)
{
Expr condition = (make_zero(Int(32)) == make_zero(Int(32))); //will try Bool(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build a Array<Expr> containing condition, use https://github.com/dmlc/tvm/blob/master/src/arithmetic/compute_expr.h#L42 to do reduction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, please check

auto vit = dom_map.find(iv);
CHECK(vit != dom_map.end());
const Range& vrange = vit->second;
Expr newcond = ( iv->var == vrange->min);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use condition

if (likely(var1> min1) or likely(var2 > min2)) {
   update
} else {
   body
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -208,5 +208,31 @@ Stmt Substitute(Stmt s,
return ir::Substitute(s, init);
}

Stmt TransformUpdate(const Stage& stage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is specific to Tensorize, move it to tensorize.cc, no need to keep comment in header file, move comment document to tensorize.cc as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, move the function into tensorize.cc

update = MergeNest(update_nest, update);
return MergeNest(common, Block::make(init, update));
} else {
// The update
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment about what this logic is about. Something like

// when init intrinsic is not available, transform to reset in the first iter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return MergeNest(common, Block::make(init, update));
} else {
// The update
Stmt update = TransformUpdate (stage, dom_map,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add CHECK(body.defined());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@tqchen tqchen changed the title when there is no intrin func, using body for initialization. For issu… [SCHEDULE] New Reduction Mode for Tensorize Dec 26, 2017
@tqchen
Copy link
Member

tqchen commented Dec 26, 2017

@tqchen
Copy link
Member

tqchen commented Dec 26, 2017

there is one additional drawback of the approach which requires additional verification. We cannot let the n.main_predicates do not contain conditions on the outer Reduce IterVar.

For example, if condition contains rc>1 (and rc is from [0, n) ), then the initial checking condition is no longer correct. Error shall be raised when such case is detected.

This can be done via something similar to https://github.com/dmlc/tvm/blob/master/src/op/tensorize.cc#L124

CHECK(intrin->reduce_init.defined())
<< "Reduction init op for intrin " << intrin << " is not defined";
// Comment out the following check for the case when there is no init func
//CHECK(intrin->reduce_init.defined())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove lgtm, simply remove them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kun-zh
Copy link
Contributor Author

kun-zh commented Dec 27, 2017

Refined the code per review comment, and add a test case in unittest, will add more cases in the following days.

@@ -0,0 +1,90 @@
import tvm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to test_schedule_tensorize.py We can use different function name

@tqchen tqchen merged commit bb6ddd2 into apache:master Dec 27, 2017
tqchen pushed a commit to tqchen/tvm that referenced this pull request Dec 31, 2017
* when there is no intrin func, using body for initialization. For issue 714.

* Refine code per review comments, and add a test case.

* Fix lint issues.
tqchen pushed a commit to tqchen/tvm that referenced this pull request Jul 6, 2018
* when there is no intrin func, using body for initialization. For issue 714.

* Refine code per review comments, and add a test case.

* Fix lint issues.
sergei-mironov pushed a commit to sergei-mironov/tvm that referenced this pull request Aug 8, 2018
* when there is no intrin func, using body for initialization. For issue 714.

* Refine code per review comments, and add a test case.

* Fix lint issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants